<?php

	require_once(TOOLKIT . '/class.event.php');
	
	Class eventedit_profile extends Event{
		
		const ROOTELEMENT = 'edit-profile';
		
		public $eParamFILTERS = array(
			
		);
			
		public static function about(){
			return array(
					 'name' => 'Edit Profile',
					 'author' => array(
							'name' => 'J G',
							'website' => 'http://localhost:8888/corvallispt.dev',
							'email' => 'elixai@gmail.com'),
					 'version' => '1.0',
					 'release-date' => '2009-11-24T13:32:02+00:00',
					 'trigger-condition' => 'action[edit-profile]');	
		}

		public static function getSource(){
			return '15';
		}

		public static function allowEditorToParse(){
			return true;
		}

		public static function documentation(){
			return '
        <h3>Success and Failure XML Examples</h3>
        <p>When saved successfully, the following XML will be returned:</p>
        <pre class="XML"><code>&lt;edit-profile result="success" type="create | edit">
  &lt;message>Entry [created | edited] successfully.&lt;/message>
&lt;/edit-profile></code></pre>
        <p>When an error occurs during saving, due to either missing or invalid fields, the following XML will be returned:</p>
        <pre class="XML"><code>&lt;edit-profile result="error">
  &lt;message>Entry encountered errors when saving.&lt;/message>
  &lt;field-name type="invalid | missing" />
  ...
&lt;/edit-profile></code></pre>
        <h3>Example Front-end Form Markup</h3>
        <p>This is an example of the form markup you can use on your frontend:</p>
        <pre class="XML"><code>&lt;form method="post" action="" enctype="multipart/form-data">
  &lt;input name="MAX_FILE_SIZE" type="hidden" value="5242880" />
  &lt;label>Email Address
    &lt;input name="fields[email-address]" type="text" />
  &lt;/label>
  &lt;label>First Name
    &lt;input name="fields[first-name]" type="text" />
  &lt;/label>
  &lt;label>Last Name
    &lt;input name="fields[last-name]" type="text" />
  &lt;/label>
  &lt;label>Client Password
    &lt;input name="fields[client-password]" type="text" />
  &lt;/label>
  &lt;label>Client Home Phone
    &lt;input name="fields[client-home-phone]" type="text" />
  &lt;/label>
  &lt;label>Client Mobile Phone
    &lt;input name="fields[client-mobile-phone]" type="text" />
  &lt;/label>
  &lt;label>Client Status
    &lt;select name="fields[client-status]">
      &lt;option value="Active">Active&lt;/option>
      &lt;option value="Closed">Closed&lt;/option>
      &lt;option value="Disabled">Disabled&lt;/option>
      &lt;option value="Suspended">Suspended&lt;/option>
    &lt;/select>
  &lt;/label>
  &lt;input name="action[edit-profile]" type="submit" value="Submit" />
&lt;/form></code></pre>
        <p>To edit an existing entry, include the entry ID value of the entry in the form. This is best as a hidden field like so:</p>
        <pre class="XML"><code>&lt;input name="id" type="hidden" value="23" /></code></pre>
        <p>To redirect to a different location upon a successful save, include the redirect location in the form. This is best as a hidden field like so, where the value is the URL to redirect to:</p>
        <pre class="XML"><code>&lt;input name="redirect" type="hidden" value="http://localhost:8888/corvallispt.dev/success/" /></code></pre>';
		}
		
		public function load(){			
			if(isset($_POST['action']['edit-profile'])) return $this->__trigger();
		}
		
		protected function __trigger(){
			include(TOOLKIT . '/events/event.section.php');
			return $result;
		}		

	}

